package com.jvm123.api.img.controller

import com.jvm123.api.util.Page
import com.jvm123.api.img.entity.Image
import com.jvm123.api.img.service.ImageService
import org.springframework.stereotype.Controller
import org.springframework.ui.Model
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.ResponseBody

import javax.annotation.Resource

/**
 *
 * @author yawn http://jvm123.com
 *     2019/12/18 10:08
 */
@Controller
@RequestMapping("img")
class ImgController {

    @Resource
    ImageService imageService

    @GetMapping("")
    String img(Model model,
             @RequestParam(defaultValue = "1") int page,
             @RequestParam(defaultValue = "10") int size) {
        if (size > 16) {
            size = 16
        }
        Page<Image> imgPage = imageService.page(page, size)
        model.addAttribute("imgPage", imgPage)
        "img"
    }

    @GetMapping("copy")
    @ResponseBody
    boolean copy() {
        imageService.copy()
    }

}
